<template>
    <a-card :bordered="false">

    <!-- 左侧面板 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="7" :sm="8">
            <a-form-item label="商品编号/名称" :labelCol="{span: 6}" :wrapperCol="{span: 14, offset: 1}">
              <a-input placeholder="请输入商品编号/名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="7" :sm="8">
            <a-form-item label="状态" :labelCol="{span: 6}" :wrapperCol="{span: 14, offset: 1}">
              <a-select v-model="queryParam.status" placeholder="请选择" default-value="null" :getPopupContainer="triggerNode => triggerNode.parentNode">
                <a-select-option value="">全部</a-select-option>
                <a-select-option value="1">禁用</a-select-option>
                <a-select-option value="0">启用</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="7" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary"  icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
      <div class="table-operator" style="border-top: 5px">
        <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      </div>
       <a-table
        ref="table"
        :scroll="{x: 1700}"
        rowKey="id"
        size="middle"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        :pagination="ipagination"
        @change="handleTableChange">
        <span  slot="status" slot-scope="text, record">   
           <a-switch :checked="record.status == 0" @click="updateBrandStatus(record,$event ? ischoose : noChoose)"></a-switch>
        </span>
        <span slot="url" slot-scope="text">
          <img :src="text" alt="" class="thumbnail" />
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)"><a-icon type="edit"/> 编辑 </a>
          <a-popconfirm title="确定删除吗?" @confirm="() =>handleDelete(record.id)">
            <a> 删除 </a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <productModal ref='modalForm' @ok="modalFormOk"></productModal>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import productModal from './modules/productModal'
import { postAction } from '@/api/manage'
import { filterObj } from '@/utils/util';

export default {
  mixins:[JeecgListMixin],
  components: {productModal},
  data() {
    return {
      ischoose: 0,
      noChoose: 1,
      description: '这是数据商品页面',
      visible: false,
      // 查询条件
      queryParam: {
        status:"",
      },
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 120,
          align: "center",
          customRender: function (t, r, index) {
              console.log(index);
            return parseInt(index) + 1;
          }
        },
        {
          title: '商品图片',
          align: "center",
          dataIndex: 'url',
          width: 100,
          scopedSlots: { customRender: 'url' }
        },
        // {
        //   title: '商品编号',
        //   align: "center",
        //   dataIndex: 'productNo',
        // },
        {
          title: '商品名称',
          align: "center",
          dataIndex: 'name',
        },
        // {
        //   title: '集团银卡价格(积分)',
        //   align: "center",
        //   dataIndex: 'integralLevel0',
        // },
        // {
        //   title: '集团金卡价格(积分)',
        //   align: "center",
        //   dataIndex: 'integralLevel1',
        // },
        // {
        //   title: '集团白金卡价格(积分)',
        //   align: "center",
        //   dataIndex: 'integralLevel2',
        // },
        // {
        //   title: '集团铂金卡价格(积分)',
        //   align: "center",
        //   dataIndex: 'integralLevel3',
        // },
        {
          title: '描述',
          align: "center",
          dataIndex: 'describe',
        },
        {
          title: '状态',
          align: "center",
          dataIndex: 'status',
          scopedSlots: {customRender: 'status'},
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: {customRender: 'action'},
          fixed:'right',
          width:150
        }
      ],
      dict: "",
      labelCol: {
        xs: {span: 8},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 16},
        sm: {span: 19},
      },
      url: {
        list: "/backend/coffee/pageProductVo",
        delete: "/backend/coffee/delProductById",
      },
    }
  },
  computed: {},
  watch: {},
  methods: {
    getQueryParams(){
      var param = Object.assign(this.queryParam);
      param.current = this.ipagination.current;
      param.size = this.ipagination.pageSize;
      return filterObj(param);
    },
    updateBrandStatus(row,event){
      let url = "/backend/coffee/saveOrUpdateProduct"
      let params={
        id:row.id,
        status:event,
        statusText:"状态"
      }
      postAction(url,params).then(res=>{
        if (res.success) {
          this.$message.success(res.msg)
          this.loadData(1)
        } else {
          this.$message.warning(res.msg)
        }
      })
    },
    // 重置搜索框的内容
    searchReset() {
      var that = this;
      that.queryParam.name = "";
      that.queryParam.status = "";
      that.loadData(this.ipagination.current);
    },
  },
}
</script>
<style scoped>
.thumbnail {
  width: 100px;
  height: 100px;
}
</style>